﻿using DevExpress.Utils;
using Lamex.Library;
using Lamex.Library.CommonClass;
using Lamex.SIESystemManager.ucControls;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Lamex.SIESystemManager.Calculate;
using Lamex.Interface;
using System.IO;
using DevExpress.XtraGrid.Views.Grid;
using Lamex.SIESystemManager.Model;
using Lamex.SIESystemManager.BLL;
using Lamex.Base;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid;

namespace Lamex.SIESystemManager.UI
{
    public partial class FrmBIEWorkHoursCalculate : frmBaseDataForm
    {
        public string Version { get; private set; }

        public FrmBIEWorkHoursCalculate()
        {
            InitializeComponent();
            InitializeForm();
            DateEditFormat();
            this.Load += new EventHandler(FrmBIEWorkHoursCalculate_Load);

        }
        public void DateEditFormat()
        {
            cbeMachineVer.Properties.Items.Clear();
            foreach (DataRow row in GetMachineVer().Rows)
            {
                cbeMachineVer.Properties.Items.Add(row["VER_NO"]);
            }
            cbeMachineVer.SelectedIndex = 0;

            this.dtStartTime.Properties.DisplayFormat.FormatString = "yyyy-MM-dd";
            this.dtStartTime.Properties.DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
            this.dtStartTime.Properties.EditFormat.FormatString = "yyyy-MM-dd";
            this.dtStartTime.Properties.EditFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
            this.dtStartTime.Properties.Mask.EditMask = "yyyy-MM-dd";

            this.dtEndTime.Properties.DisplayFormat.FormatString = "yyyy-MM-dd";
            this.dtEndTime.Properties.DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
            this.dtEndTime.Properties.EditFormat.FormatString = "yyyy-MM-dd";
            this.dtEndTime.Properties.EditFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
            this.dtEndTime.Properties.Mask.EditMask = "yyyy-MM-dd";

            this.dtEffective.Properties.DisplayFormat.FormatString = "yyyy-MM-dd";
            this.dtEffective.Properties.DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
            this.dtEffective.Properties.EditFormat.FormatString = "yyyy-MM-dd";
            this.dtEffective.Properties.EditFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
            this.dtEffective.Properties.Mask.EditMask = "yyyy-MM-dd";

            dtStartTime.Text = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd");
            dtEndTime.Text = DateTime.Now.AddDays(6).ToString("yyyy-MM-dd");
            dtEffective.Text = DateTime.Now.ToString("yyyy-MM-dd");

            gridView2.BestFitColumns();
            gridView2.OptionsView.ColumnAutoWidth = false;
        }
        private void FrmBIEWorkHoursCalculate_Load(object sender, EventArgs e)
        {
            try { this.InitButtons(); } catch { }//初始化标准功能，因要应用于RibbonForm，所以加入异常处理
        }

        //机器时间版本
        public DataTable GetMachineVer()
        {
            DataTable dt = new DataTable();
            string sqlThickness = @"   select  distinct '' VER_NO from[LamexMESManager].[dbo].[B_IE_Machine_Version]  union all 
  select distinct VER_NO from[LamexMESManager].[dbo].[B_IE_Machine_Version] where Flag=1";
            dt = BaseBuildSql.GetDataTableBySql(sqlThickness);
            return dt;
        }

        protected override void InitializeForm()
        {
            _SummaryView = new DevGridView(gridView2);
            gridView2.DoubleClick += new EventHandler(OnGridViewDoubleClick); //主表DoubleClict
            frmGridViewCust.RegisterGrid(gridView2);
            DevStyle.SetGridControlLayout(gcView, false);//表格设置   

            DevStyle.SetSummaryGridViewLayout(gridView2);
            DevStyle.SetDetailGridViewLayout(gridView2);
            ShowSummary(); //下载显示数据.
            tpSummary = xtraTabPage1;
            tcBusiness = xtraTabControl1;
            tpSummary.PageVisible = true;
            //tpDetail.PageVisible = false;
            tcBusiness.ShowTabHeader = DefaultBoolean.True;
            tcBusiness.SelectedTabPage = tpSummary;
            //ShowSummaryPage(true); //一切初始化完毕後显示SummaryPage  
        }
        private void ShowSummary()
        {
            try
            {
                //
                //ucLookUpEdit1.ValueMember = "UserName";
                //ucLookUpEdit1.DisPlayMember = "UserName";
                //ucLookUpEdit1.DataSource = dt;
                ////ucLookUpEdit1.UcPopulateColumns();

                ////ucLookUpEdit1.Item[1].Caption = "用户名称";
                //////ucLookUpEdit1.ForceInitialize();
                ////ucLookUpEdit1.UcItemIndex = 0;
                //DoBindingSummaryGrid(dt); //绑定主表的Grid
                //ShowSummaryPage(true); //显示Summary页面. 
                xtraTabPage2.PageEnabled = false;
                xtraTabPage1.PageEnabled = true;

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        /// <summary>
        /// 计算工时
        /// </summary>
        /// <param name="sender"></param>
        public override void DoCalculate(Lamex.Interface.IButtonInfo sender)
        {
            #region 按钮权限
            if (!BuildSqlHelper.IsExistList("B_IE_WorkTimeHistory", "LamexMESManager")) return;
            #endregion
            //一定要选择时间
            if (string.IsNullOrEmpty(dtStartTime.Text))
            {
                DevExpress.XtraEditors.XtraMessageBox.Show("请选择开始时间", "提示", MessageBoxButtons.OK);
                return;
            }
            if (string.IsNullOrEmpty(dtEndTime.Text))
            {
                DevExpress.XtraEditors.XtraMessageBox.Show("请选择结束时间", "提示", MessageBoxButtons.OK);
                return;
            }

            if (string.IsNullOrEmpty(dtEffective.Text))
            {
                DevExpress.XtraEditors.XtraMessageBox.Show("请选择生效时间", "提示", MessageBoxButtons.OK);
                return;
            }
            //if (string.IsNullOrEmpty(cbeMachineVer.Text))
            //{
            //    DevExpress.XtraEditors.XtraMessageBox.Show("请选择机器时间版本", "提示", MessageBoxButtons.OK);
            //    return;
            //}
            GetSqlData gd = new GetSqlData();
            GetOperation_Data gOperate = new GetOperation_Data();
            C_D04 c_d04 = new C_D04();
            C_D07 c_d07 = new C_D07();
            C_D11 c_d11 = new C_D11();
            C_D14 c_d14 = new C_D14();
            C_D21 c_d21 = new C_D21();
            C_D24 c_d24 = new C_D24();
            C_D27 c_d27 = new C_D27();
            C_D28 c_d28 = new C_D28();
            C_D29 c_d29 = new C_D29();
            C_D30 c_d30 = new C_D30();
            C_D31 c_d31 = new C_D31();
            C_D32 c_d32 = new C_D32();
            C_D34 c_d34 = new C_D34();
            C_D37 c_d37 = new C_D37();
            C_D41 c_d41 = new C_D41();
            C_D42 c_d42 = new C_D42();
            C_Routing_Group c_routing = new C_Routing_Group();
            GetWorkHourTable dt = new GetWorkHourTable();
            StringBuilder sbDRAWING = new StringBuilder();
            StringBuilder sbPartNumber = new StringBuilder();
            string strDRAWING = txtDRAWING_NUMBER.Text.Trim();//图纸号
            string strStartTime = dtStartTime.Text.Trim();//开始时间
            string strEndTime = dtEndTime.Text.Trim();//结束时间
            string strEffective = dtEffective.Text.Trim();//生效时间
            int Serial = 0, Routing_Group = 0, Calculate = 0;//代码组和流水号计数
            List<double> RoutingList = new List<double>();//代码组描述
            bool first = true;//用于判断是否第一次执行
            string Routing_dec = "";
            double TD01 = 0, TD04 = 0, TD07 = 0, TD11 = 0, TD14 = 0, TD17 = 0, TD21 = 0, TD24 = 0,
                    TD27 = 0, TD28 = 0, TD29 = 0, TD30 = 0, TD31 = 0, TD32 = 0, TD34 = 0, TD37 = 0,
                    TD41 = 0, TD42 = 0, TD44 = 0, TD47 = 0, TD51 = 0, TD54 = 0;
            string Machine_flag11 = "0", Machine_flag21 = "0", Machine_flag32 = "0", Machine_flag30 = "0";

            string[] str1 = strDRAWING.Split(new string[] { "\r\n" }, StringSplitOptions.None);
            if (str1[0].Length > 0)
            {
                sbDRAWING.AppendFormat(" AND A.Drawing_Num IN('{0}') ", string.Join("','", str1.ToArray()));
            }
            else
            {
                sbDRAWING.AppendFormat("");
            }
            string strPartNumber = txtPART_NO.Text.Trim();//部件号
            string[] str2 = strPartNumber.Split(new string[] { "\r\n" }, StringSplitOptions.None);
            if (str2[0].Length > 0)
            {
                sbPartNumber.AppendFormat(" AND A.PartNumber IN('{0}') ", string.Join("','", str2.ToArray()));
            }
            else
            {
                sbPartNumber.AppendFormat("");
            }
            SplashScreenTool.ShowSplashScreen(typeof(WaitForm1));
            //using (DevExpress.Utils.WaitDialogForm wdf = new DevExpress.Utils.WaitDialogForm("请稍等", "正在查询数据......", new Size(400, 80)))
            //{
            try
            {
                DataTable dtall = gd.GetSql(sbDRAWING.ToString(), sbPartNumber.ToString(), strStartTime, strEndTime);//获取所有部件号数据             
                DataTable dtOperational = gOperate.GetOperationSql(strEffective);//获取工序动作对应的单位工时--增加生效时间
                DataTable dtFactor = gOperate.GetFactor(strEffective);//获取宽放系数--增加生效时间
                DataTable dtMachine = gOperate.GetMachineData(cbeMachineVer.Text);//获取机器数据
                DataTable dtNew = dt.GetTable_New();//定义-动态生成输出表
                DataRow dr = dtNew.NewRow();//定义-动态生成输出行
                DataTable dtRouting = c_routing.GetTable_Routing();//工艺路线流水号输出表
                DataRow drRouting = dtRouting.NewRow();//路线代码组输出表
                DataTable dtSerial = gOperate.GetRouting();
                DataRow drser = dtSerial.Select("1=1", "IDNO ASC").LastOrDefault();//主表最后一行数据
                //特殊处理 之前把不是44组别的也查出来，往后累计，导致组别异常，但是出现异常的组别不能重新增加，需要保留，后续新的才新增
                DataTable dtSerialTemp = gOperate.GetRouting_Temp();

                if (dtall.Rows.Count == 0)
                {
                    DevExpress.XtraEditors.XtraMessageBox.Show("查无数据，请确认是否有录入特征或时间范围是否选择正确！", "提示", MessageBoxButtons.OK);
                    gcView.DataSource = dtNew;//前台显示
                    return;
                }
                if (dtall.Rows.Count > 0)
                {
                    for (int j = 0; j < dtall.Rows.Count; j++)
                    {
                        string[] ListRouting = dtall.Rows[j]["routing"].ToString().Split('-');//得到图纸的工艺路线
                        #region 插入行 工时结果表
                        dr = dtNew.NewRow();
                        //dr["PART_NUMBER"] = dtall.Rows[j]["PartNumber"].ToString();//部件号
                        //dr["DRAWING_NUMBER"] = dtall.Rows[j]["Drawing_Num"].ToString();//图纸号
                        //dr["Width_1"] = dtall.Rows[j]["Width_1"].ToString();//W1
                        //dr["Depth_1"] = dtall.Rows[j]["Depth_1"].ToString();//D1
                        //dr["Width_2"] = dtall.Rows[j]["Width_2"].ToString();//W2
                        //dr["Depth_2"] = dtall.Rows[j]["Depth_2"].ToString();//D2
                        //dr["Thickness"] = dtall.Rows[j]["Thickness"].ToString();//厚度
                        //dr["D_Cutting_Size"] = dtall.Rows[j]["D_Cutting_Size"].ToString();//切割尺寸
                        //dr["WORKCENTER_NUMBER"] = dtall.Rows[j]["routing"].ToString();//工艺路线
                        //dr["DESCRIBE"] = dtall.Rows[j]["Description"].ToString();//部件描述
                        ////dr["GROUP_CODE"] = dtall.Rows[j]["GROUP_CODE"].ToString();//组
                        //// dr["CALCULATE_DESC"] = dtall.Rows[j]["GROUP_DEC"].ToString();//计算器描述
                        ////dr["CALCULATES"] = 1;//计算器
                        //dr["WEEKS"] = 30;//周期
                        dr["PartNumber"] = dtall.Rows[j]["PartNumber"].ToString();//部件号
                        dr["DrawNum"] = dtall.Rows[j]["Drawing_Num"].ToString();//图纸号
                        dr["Width_1"] = dtall.Rows[j]["Width_1"].ToString();//W1
                        dr["Dedth_1"] = dtall.Rows[j]["Depth_1"].ToString();//D1
                        dr["Width_2"] = dtall.Rows[j]["Width_2"].ToString();//W2
                        dr["Dedth_2"] = dtall.Rows[j]["Depth_2"].ToString();//D2
                        dr["Tinckness"] = dtall.Rows[j]["Thickness"].ToString();//厚度
                        dr["D_Cutting_Size"] = dtall.Rows[j]["D_Cutting_Size"].ToString();//切割尺寸
                        dr["WorkCenterNumber"] = dtall.Rows[j]["routing"].ToString();//工艺路线
                        dr["Decription"] = dtall.Rows[j]["Description"].ToString();//部件描述
                        dr["Cycle"] = 0;//周期
                        dr["CreateDate"] = DateTime.Now;
                        dr["Flag"] = "1";
                        #endregion

                        foreach (var item in ListRouting)
                        {
                            switch (item.ToString())
                            {
                                case "D01":
                                    TD01 = 16;
                                    dr["D01"] = TD01;
                                    RoutingList.Add(TD01);
                                    break;
                                case "D04":
                                    TD04 = Math.Ceiling(c_d04.GetD04(dtall.Rows[j]["Width_1"].ToString(), dtall.Rows[j]["Width_2"].ToString())
                                        * (dtFactor.Select("PROCESS_CODE='D04'").Length <= 0 ? 1 :
                                         1 + Convert.ToDouble(dtFactor.Select(("PROCESS_CODE='D04'"))[0].ItemArray[1].ToString())));
                                    dr["D04"] = TD04;
                                    RoutingList.Add(TD04);
                                    break;
                                case "D07":
                                    TD07 = Math.Ceiling(c_d07.GetD07(dtall.Rows[j]["Width_1"].ToString(), dtall.Rows[j]["Width_2"].ToString())
                                         * (dtFactor.Select("PROCESS_CODE='D07'").Length <= 0 ? 1 :
                                        1 + Convert.ToDouble(dtFactor.Select(("PROCESS_CODE='D07'"))[0].ItemArray[1].ToString())));
                                    dr["D07"] = TD07;
                                    RoutingList.Add(TD07);
                                    break;
                                case "D11":
                                    if (string.IsNullOrEmpty(cbeMachineVer.Text))
                                    {
                                        double[] ArrayTD11 = c_d11.GetD11(dtall.Select("Drawing_Num='" + dtall.Rows[j]["Drawing_Num"].ToString() + "' and PartNumber='" + dtall.Rows[j]["PartNumber"].ToString() + "'"),
                                           dtOperational.Select("WORKSTATION_LIST like '%D11%'"),
                                            // dtMachine.Select("Part_No='" + dtall.Rows[j]["PartNumber"].ToString() + "' and Machine_Name='D11'"));
                                         null);//机器时间
                                        TD11 = ArrayTD11[0];
                                        Machine_flag11 = ArrayTD11[1].ToString() == "1" ? "PH" : "0";

                                        dr["D11"] = Math.Ceiling(TD11 * (dtFactor.Select("PROCESS_CODE='D11'").Length <= 0 ? 1 :
                                           1 + Convert.ToDouble(dtFactor.Select(("PROCESS_CODE='D11'"))[0].ItemArray[1].ToString())));
                                        RoutingList.Add(Convert.ToDouble(dr["D11"]));
                                    }
                                    else
                                    {
                                        double[] ArrayTD11 = c_d11.GetD11(dtall.Select("Drawing_Num='" + dtall.Rows[j]["Drawing_Num"].ToString() + "' and PartNumber='" + dtall.Rows[j]["PartNumber"].ToString() + "'"),
                                            dtOperational.Select("WORKSTATION_LIST like '%D11%'"),
                                           dtMachine.Select("Part_No='" + dtall.Rows[j]["PartNumber"].ToString() + "' and Machine_Name='D11'"));
                                        // 0);//机器时间
                                        TD11 = ArrayTD11[0];
                                        Machine_flag11 = ArrayTD11[1].ToString() == "1" ? "PH" : "0";

                                        dr["D11"] = Math.Ceiling(TD11 * (dtFactor.Select("PROCESS_CODE='D11'").Length <= 0 ? 1 :
                                           1 + Convert.ToDouble(dtFactor.Select(("PROCESS_CODE='D11'"))[0].ItemArray[1].ToString())));
                                        RoutingList.Add(Convert.ToDouble(dr["D11"]));
                                    }
                                    break;
                                case "D14":
                                    TD14 = Math.Ceiling(c_d14.GetD14(dtall.Rows[j]["Width_1"].ToString(), dtall.Rows[j]["Width_2"].ToString())
                                         * (dtFactor.Select("PROCESS_CODE='D14'").Length <= 0 ? 1 :
                                        1 + Convert.ToDouble(dtFactor.Select(("PROCESS_CODE='D14'"))[0].ItemArray[1].ToString())));
                                    dr["D14"] = Math.Ceiling(TD14);
                                    RoutingList.Add(TD14);
                                    break;
                                case "D17":
                                    TD17 = 24;
                                    dr["D17"] = TD17;
                                    RoutingList.Add(TD17);
                                    break;
                                case "D21":
                                    if (string.IsNullOrEmpty(cbeMachineVer.Text))
                                    {
                                        double[] ArrayTD21 = c_d21.GetD21(dtall.Select("Drawing_Num='" + dtall.Rows[j]["Drawing_Num"].ToString() + "' and PartNumber='" + dtall.Rows[j]["PartNumber"].ToString() + "'"),
                                           dtOperational.Select("WORKSTATION_LIST like '%D21%'"),
                                           dtall.Rows[j]["D21_Component_Type"].ToString(),
                                            //dtMachine.Select("Part_No='" + dtall.Rows[j]["PartNumber"].ToString() + "' and Machine_Name='D21'"));
                                         null);//机器时间
                                        TD21 = ArrayTD21[0];
                                        Machine_flag21 = ArrayTD21[1].ToString() == "1" ? "BIMA" : "0";

                                        dr["D21"] = Math.Ceiling(TD21 * (dtFactor.Select("PROCESS_CODE='D21'").Length <= 0 ? 1 :
                                            1 + Convert.ToDouble(dtFactor.Select(("PROCESS_CODE='D21'"))[0].ItemArray[1].ToString())));
                                        RoutingList.Add(Convert.ToDouble(dr["D21"]));
                                    }
                                    else
                                    {
                                        double[] ArrayTD21 = c_d21.GetD21(dtall.Select("Drawing_Num='" + dtall.Rows[j]["Drawing_Num"].ToString() + "' and PartNumber='" + dtall.Rows[j]["PartNumber"].ToString() + "'"),
                                           dtOperational.Select("WORKSTATION_LIST like '%D21%'"),
                                           dtall.Rows[j]["D21_Component_Type"].ToString(),
                                           dtMachine.Select("Part_No='" + dtall.Rows[j]["PartNumber"].ToString() + "' and Machine_Name='D21'"));
                                        // 0 );//机器时间
                                        TD21 = ArrayTD21[0];
                                        Machine_flag21 = ArrayTD21[1].ToString() == "1" ? "BIMA" : "0";

                                        dr["D21"] = Math.Ceiling(TD21 * (dtFactor.Select("PROCESS_CODE='D21'").Length <= 0 ? 1 :
                                            1 + Convert.ToDouble(dtFactor.Select(("PROCESS_CODE='D21'"))[0].ItemArray[1].ToString())));
                                        RoutingList.Add(Convert.ToDouble(dr["D21"]));
                                    }
                                    break;
                                case "D24":
                                    TD24 = Math.Ceiling(c_d24.GetD24(dtall.Select("Drawing_Num='" + dtall.Rows[j]["Drawing_Num"].ToString() + "' and PartNumber='" + dtall.Rows[j]["PartNumber"].ToString() + "'"),
                                        dtOperational.Select("WORKSTATION_LIST like '%D24%'"))
                                         * (dtFactor.Select("PROCESS_CODE='D24'").Length <= 0 ? 1 :
                                        1 + Convert.ToDouble(dtFactor.Select(("PROCESS_CODE='D24'"))[0].ItemArray[1].ToString())));
                                    dr["D24"] = TD24;
                                    RoutingList.Add(TD24);
                                    break;
                                case "D27":
                                    TD27 = Math.Ceiling(c_d27.GetD27(dtall.Select("Drawing_Num='" + dtall.Rows[j]["Drawing_Num"].ToString() + "' and PartNumber='" + dtall.Rows[j]["PartNumber"].ToString() + "'"),
                                        dtOperational.Select("WORKSTATION_LIST like '%D27%'"))
                                        * (dtFactor.Select("PROCESS_CODE='D27'").Length <= 0 ? 1 :
                                        1 + Convert.ToDouble(dtFactor.Select(("PROCESS_CODE='D27'"))[0].ItemArray[1].ToString())));
                                    dr["D27"] = TD27;
                                    RoutingList.Add(TD27);
                                    break;
                                case "D28":
                                    TD28 = Math.Ceiling(c_d28.GetD28(dtall.Rows[j]["Width_1"].ToString(), dtall.Rows[j]["Width_2"].ToString(), dtall.Rows[j]["D28_Sealing_Diagonal_Edge"].ToString())
                                         * (dtFactor.Select("PROCESS_CODE='D28'").Length <= 0 ? 1 :
                                        1 + Convert.ToDouble(dtFactor.Select(("PROCESS_CODE='D28'"))[0].ItemArray[1].ToString())));
                                    dr["D28"] = TD28;
                                    RoutingList.Add(TD28);
                                    break;
                                case "D29":
                                    TD29 = Math.Ceiling(c_d29.GetD29(dtall.Rows[j]["Width_1"].ToString(), dtall.Rows[j]["Width_2"].ToString(), dtall.Rows[j]["D29_Seal_Straight_Line_Edge"].ToString())
                                         * (dtFactor.Select("PROCESS_CODE='D29'").Length <= 0 ? 1 :
                                        1 + Convert.ToDouble(dtFactor.Select(("PROCESS_CODE='D29'"))[0].ItemArray[1].ToString())));
                                    dr["D29"] = TD29;
                                    RoutingList.Add(TD29);
                                    break;
                                case "D30":
                                    double[] ArrayTD30 = c_d30.GetD30(dtall.Select("Drawing_Num='" + dtall.Rows[j]["Drawing_Num"].ToString() + "' and PartNumber='" + dtall.Rows[j]["PartNumber"].ToString() + "'"),
                                        dtOperational.Select("WORKSTATION_LIST like '%D30%'"),
                                        //Convert.ToDouble(gOperate.GetMachineData("D11", dtall.Rows[j]["PartNumber"].ToString()).Rows[0][0].ToString())
                                       0);//机器时间
                                    TD30 = ArrayTD30[0];
                                    Machine_flag30 = ArrayTD30[1].ToString();
                                    dr["D30"] = Math.Ceiling(TD30 * (dtFactor.Select("PROCESS_CODE='D30'").Length <= 0 ? 1 :
                                       1 + Convert.ToDouble(dtFactor.Select(("PROCESS_CODE='D30'"))[0].ItemArray[1].ToString())));
                                    RoutingList.Add(Convert.ToDouble(dr["D30"]));
                                    break;
                                case "D31":
                                    TD31 = Math.Ceiling(c_d31.GetD31(dtall.Rows[j]["Width_1"].ToString(), dtall.Rows[j]["Width_2"].ToString(), dtall.Rows[j]["D31_Seal_Straight_Line_Edge"].ToString())
                                         * (dtFactor.Select("PROCESS_CODE='D31'").Length <= 0 ? 1 :
                                        1 + Convert.ToDouble(dtFactor.Select(("PROCESS_CODE='D31'"))[0].ItemArray[1].ToString())));
                                    dr["D31"] = TD31;
                                    RoutingList.Add(TD31);
                                    break;
                                case "D32":
                                    double[] ArrayTD32 = c_d32.GetD32(dtall.Select("Drawing_Num='" + dtall.Rows[j]["Drawing_Num"].ToString() + "' and PartNumber='" + dtall.Rows[j]["PartNumber"].ToString() + "'"),
                                       dtOperational.Select("WORKSTATION_LIST like '%D32%'"),
                                       dtall.Rows[j]["D32_Component_Type"].ToString(),
                                        //  Convert.ToDouble(gOperate.GetMachineData("D32", dtall.Rows[j]["PartNumber"].ToString()).Rows[0][0].ToString())//机器时间
                                    0);//暂时取0
                                    TD32 = ArrayTD32[0] * 1.5;
                                    Machine_flag32 = ArrayTD32[1].ToString();
                                    dr["D32"] = Math.Ceiling(TD32 * (dtFactor.Select("PROCESS_CODE='D32'").Length <= 0 ? 1 :
                                    1 + Convert.ToDouble(dtFactor.Select(("PROCESS_CODE='D32'"))[0].ItemArray[1].ToString())));
                                    RoutingList.Add(Convert.ToDouble(dr["D32"]));
                                    break;
                                case "D34":
                                    TD34 = Math.Ceiling(c_d34.GetD34(dtall.Select("Drawing_Num='" + dtall.Rows[j]["Drawing_Num"].ToString() + "' and PartNumber='" + dtall.Rows[j]["PartNumber"].ToString() + "'"),
                                        dtOperational.Select("WORKSTATION_LIST like '%D34%'"),
                                        dtall.Rows[j]["D34_Component_Type"].ToString(),
                                        dtall.Rows[j]["D34_Edge_Thickness"].ToString())
                                         * (dtFactor.Select("PROCESS_CODE='D34'").Length <= 0 ? 1 :
                                         1 + Convert.ToDouble(dtFactor.Select(("PROCESS_CODE='D34'"))[0].ItemArray[1].ToString())));
                                    dr["D34"] = TD34;
                                    RoutingList.Add(TD34);
                                    break;
                                case "D37":
                                    TD37 = Math.Ceiling((c_d37.GetD37(dtall.Select("Drawing_Num='" + dtall.Rows[j]["Drawing_Num"].ToString() + "' and PartNumber='" + dtall.Rows[j]["PartNumber"].ToString() + "'"),
                                        dtOperational.Select("WORKSTATION_LIST like '%D37%'"), dtall.Rows[j]["routing"].ToString()))
                                         * (dtFactor.Select("PROCESS_CODE='D37'").Length <= 0 ? 1 :
                                         1 + Convert.ToDouble(dtFactor.Select(("PROCESS_CODE='D37'"))[0].ItemArray[1].ToString())));
                                    dr["D37"] = TD37;
                                    RoutingList.Add(TD37);
                                    break;
                                case "D41":
                                    TD41 = Math.Ceiling(c_d41.GetD41(dtall.Select("Drawing_Num='" + dtall.Rows[j]["Drawing_Num"].ToString() + "' and PartNumber='" + dtall.Rows[j]["PartNumber"].ToString() + "'"),
                                        dtOperational.Select("WORKSTATION_LIST like '%D41%'"), dtall.Rows[j]["routing"].ToString())
                                         * (dtFactor.Select("PROCESS_CODE='D41'").Length <= 0 ? 1 :
                                        1 + Convert.ToDouble(dtFactor.Select(("PROCESS_CODE='D41'"))[0].ItemArray[1].ToString())));
                                    dr["D41"] = TD41;
                                    RoutingList.Add(TD41);
                                    break;
                                case "D42":
                                    TD42 = Math.Ceiling(c_d42.GetD42(dtall.Rows[j]["Width_1"].ToString(),
                                        dtall.Rows[j]["Width_2"].ToString(),
                                         dtall.Rows[j]["GROUP_CODE"].ToString()));
                                    dr["D42"] = TD42;
                                    RoutingList.Add(TD42);
                                    break;
                            }

                        }
                        #region 工艺代码组赋值
                       // if (RoutingList.Count == 0)
                        if (string.IsNullOrEmpty(dtall.Rows[j]["GROUP_CODE"].ToString()))
                        {
                            DevExpress.XtraEditors.XtraMessageBox.Show("部件号:" + dtall.Rows[j]["PartNumber"].ToString() + "无工艺路线简码，请检查确认！", "提示", MessageBoxButtons.OK);
                            return;
                        }
                         if (RoutingList.Count == 0)                     
                        {
                            DevExpress.XtraEditors.XtraMessageBox.Show("部件号:" + dtall.Rows[j]["PartNumber"].ToString() + "所有工序工时为0，请检查特征是否录入正确！", "提示", MessageBoxButtons.OK);
                            return;
                        }
                        foreach (var list in RoutingList)
                        {
                            Routing_dec += list + "_";
                        }
                        dr["CountDecription"] = dtall.Rows[j]["GROUP_CODE"].ToString() + "_" + Routing_dec.Substring(0, Routing_dec.Length - 1);//代码组描述
                        //获取计数流水和组别
                      
                        DataRow drTemp = dtRouting.Select("1=1", "Serial ASC").LastOrDefault();//临时表最后一行数据
                        drRouting = dtRouting.NewRow();//路线代码组输出表   
                        DataRow[] drTemp2 = dtSerial.Select("Calculate_Desc='" + dr["CountDecription"] + "'");//主表
                        DataRow[] drTemp1 = dtRouting.Select("Calculate_Desc='" + dr["CountDecription"] + "'");//临时表
                        DataRow[] drTemp3 = dtSerialTemp.Select("Calculate_Desc='" + dr["CountDecription"] + "'");//主表-特殊计算 后续可删除
                        if (drTemp3.Length > 0)
                        {
                            dr["GROUP_CODE"] = drTemp3[0]["Routing_Group"];
                            dr["iCount"] = drTemp3[0]["Calculate"];
                        }
                        else if (drTemp2.Length > 0)
                        {

                            dr["GROUP_CODE"] = drTemp2[0]["Routing_Group"];
                            dr["iCount"] = drTemp2[0]["Calculate"];
                        }
                        else
                        {
                            if (drTemp1.Length > 0)
                            {

                                dr["GROUP_CODE"] = drTemp1[0]["Routing_Group"];
                                dr["iCount"] = drTemp1[0]["Calculate"];

                            }
                            else
                            {
                                if (first)
                                {
                                    Serial = 1;
                                    if (drser != null)
                                    {
                                        if (Convert.ToInt32(drser["Calculate"]) >= 2 && Convert.ToInt32(drser["Calculate"]) < 99)
                                        {
                                            drRouting["Routing_Group"] = Convert.ToInt32(drser["Routing_Group"]);
                                            drRouting["Calculate"] = Convert.ToInt32(drser["Calculate"]) + 1;

                                        }
                                        else if (Convert.ToInt32(drser["Calculate"]) == 99)
                                        {
                                            drRouting["Routing_Group"] = Convert.ToInt32(drser["Routing_Group"]) + 1;
                                            drRouting["Calculate"] = 2;
                                        }
                                    }
                                    else
                                    {
                                        drRouting["Routing_Group"] = 44000001;
                                        drRouting["Calculate"] = 2;
                                    }
                                    dr["GROUP_CODE"] = drRouting["Routing_Group"];
                                    dr["iCount"] = drRouting["Calculate"];
                                    Routing_Group = Convert.ToInt32(drRouting["Routing_Group"]);
                                    Calculate = Convert.ToInt32(drRouting["Calculate"]);
                                }
                                else
                                {
                                    Serial = Convert.ToInt32(drTemp["Serial"]) + 1;
                                    if (drTemp != null)
                                    {
                                        if (Convert.ToInt32(drTemp["Calculate"]) >= 2 && Convert.ToInt32(drTemp["Calculate"]) < 99)
                                        {
                                            drRouting["Routing_Group"] = Convert.ToInt32(drTemp["Routing_Group"]);
                                            drRouting["Calculate"] = Convert.ToInt32(drTemp["Calculate"]) + 1;

                                        }
                                        else if (Convert.ToInt32(drTemp["Calculate"]) == 99)
                                        {
                                            drRouting["Routing_Group"] = Convert.ToInt32(drTemp["Routing_Group"]) + 1;
                                            drRouting["Calculate"] = 2;
                                        }
                                    }
                                    else
                                    {
                                        drRouting["Routing_Group"] = 44000001;
                                        drRouting["Calculate"] = 2;
                                    }
                                    dr["GROUP_CODE"] = drRouting["Routing_Group"];
                                    dr["iCount"] = drRouting["Calculate"];
                                    Routing_Group = Convert.ToInt32(drRouting["Routing_Group"]);
                                    Calculate = Convert.ToInt32(drRouting["Calculate"]);
                                }
                                //}
                                //存在的数据不需要插入到数据库
                                // drRouting = dtRouting.NewRow();//路线代码组输出表                     
                                drRouting["Serial"] = Serial;
                                drRouting["Routing_Group"] = Routing_Group;
                                drRouting["Calculate"] = Calculate;
                                drRouting["Calculate_Desc"] = dr["CountDecription"];
                                drRouting["Date_TS"] = DateTime.Now;
                                drRouting["Update_User"] = Lamex.Common.Loginer.CurrentUser.AccountName;
                                dtRouting.Rows.Add(drRouting);
                                first = false;
                            }
                        }
                        #endregion
                        //机器标识
                        dr["Machine_Flag"] = Machine_flag11 + "," + Machine_flag21 + "," + Machine_flag32;
                        dtNew.Rows.Add(dr);
                        #region 插入临时表后数据全部初始化为0
                        TD01 = 0;
                        TD04 = 0;
                        TD07 = 0;
                        TD11 = 0;
                        TD14 = 0;
                        TD17 = 0;
                        TD21 = 0;
                        TD24 = 0;
                        TD27 = 0;
                        TD28 = 0;
                        TD29 = 0;
                        TD30 = 0;
                        TD31 = 0;
                        TD32 = 0;
                        TD34 = 0;
                        TD37 = 0;
                        TD41 = 0;
                        TD42 = 0;
                        TD44 = 0;
                        TD47 = 0;
                        TD51 = 0;
                        TD54 = 0;
                        Machine_flag11 = "0";
                        Machine_flag21 = "0";
                        Machine_flag32 = "0";
                        Machine_flag30 = "0";
                        RoutingList = new List<double>();
                        Routing_dec = "";
                        Serial = 0;
                        Routing_Group = 0;
                        Calculate = 0;
                        #endregion

                    }
                }
                //工艺路线流水号批量插入主表-B_IE_Calculator_Routing
                if (BaseBuildSql.ExcuteInsert(dtRouting, "B_IE_Calculator_Routing"))
                {

                    dtRouting = new DataTable();
                }
                StringBuilder sbFilter = new StringBuilder();
                StringBuilder sbFilterSJ = new StringBuilder();
                StringBuilder sbFilterST = new StringBuilder();
                List<string> delete = new List<string>();
                if (dtNew.Rows.Count > 0)
                {
                    for (int i = 0; i < dtNew.Rows.Count; i++)
                    {
                        delete.Add(dtNew.Rows[i][0].ToString());
                    }
                    sbFilter.AppendFormat(@"  PartNumber IN ('{0}')", string.Join("','", delete.ToArray()));
                    string sqlDel = @"Delete  FROM [LamexMESManager].[dbo].[B_IE_WorkTimeHistory] where " + sbFilter + "";
                    int n = BaseBuildSql.ExecuteNonQuery(sqlDel);

                }
                if (BaseBuildSql.ExcuteInsert(dtNew, "B_IE_WorkTimeHistory"))
                {

                }
                //绑定前重新定义列名，方便IE导出上传
                //gridView2.OptionsBehavior.AutoPopulateColumns = false;   
                gridView2.BestFitColumns();
                gridView2.OptionsView.ColumnAutoWidth = false;

                gcView.DataSource = dtNew;//前台显示
                //清空输入框
                txtDRAWING_NUMBER.Text = "";
                txtPART_NO.Text = "";
                ////执行储存过程--工时数据更新到IE_Part_ProcessTime
                //List<string> lst1 = new List<string>();
                //lst1.Add("1");
                //BaseBuildSql.GetProDataTable("p_IE_IED_TransForm", lst1);
            }
            catch(Exception ex)
            {
                XtraMessageBox.Show(ex.Message);
            }          
            SplashScreenTool.CloseSplashScreen();
            //}
        }

        public override void DoExport(IButtonInfo sender)
        {
            //#region 导出方法1
            //try
            //{
            //    SaveFileDialog dlg = new SaveFileDialog();
            //    //dlg.Filter = "PDF file(*.pdf)|*.pdf";
            //    dlg.Filter = "Excel文件(*.xls)|*.xls";
            //    DialogResult dialogResult = dlg.ShowDialog(this);
            //    if (dialogResult == DialogResult.OK)
            //    {
            //        gcView.ExportToXls(dlg.FileName);
            //        DevExpress.XtraEditors.XtraMessageBox.Show("导出成功", "提示", MessageBoxButtons.OK);
            //    }
            //}
            //catch (Exception ex)
            //{
            //    MessageBox.Show(ex.Message);
            //}
            //#endregion


            //导出方法2
            //if (gridView2.DataRowCount < 0) return;
            //ExportToExcel(gridView2, "标准工时计算");
            //base.DoExport(sender);

            //导出方法3
            if (!Directory.Exists(@"C:\SAPTEMP"))
                Directory.CreateDirectory(@"C:\SAPTEMP");
            SaveFileDialog fileDialog = new SaveFileDialog();
            fileDialog.Title = "导出txt";
            fileDialog.InitialDirectory = @"C:\SAPTEMP";//导出默认路径
            fileDialog.Filter = "Txt文件(*.txt)|*.txt";//导出默认格式
            fileDialog.FileName = "ZPYX_UPLOAD";//导出默认名称
            DialogResult dialogResult = fileDialog.ShowDialog(this);
            if (dialogResult == DialogResult.OK)
            {
                if (gridView2.DataRowCount <= 0) return;
                List<string> list1 = new List<string>();
                StringBuilder s1 = new StringBuilder();
                System.Data.DataTable dt = (gridView2.DataSource as System.Data.DataView).Table;
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    list1.Add(dt.Rows[i]["PartNumber"].ToString());
                }
                s1.AppendFormat(@" AND PartNumber IN ('{0}')", string.Join("','", list1.ToArray()));
                string sql = @" SELECT 
       [PartNumber] as '部件/组件'
      ,[Decription] as '描述'
      ,[GROUP_CODE] as '组'
      ,[CountDecription] as '计数器描述'
      ,[iCount] as '计数器'
      ,[Cycle] as '周期(H)'
      ,[D01] as 'D01_主线-自动仓库'
      ,[D04] as 'D04_主线-开料LS1'
      ,[D07] as 'D07_主线-COMBIMA'
      ,[D11] as 'D11_主线-钻孔P&H'
      ,[D14] as 'D14_主线-开料FH4'
      ,[D17] as 'D17_主线-翻板机'
      ,[D21] as 'D21_主线-BIMA'
      ,[D24] as 'D24_小板线'
      ,[D30] as 'D30_斜边线-数控钻'
      ,[D27] as 'D27_主线装配区'
      ,[D28] as 'D28_斜边线-斜封边'
      ,[D29] as 'D29_斜边线-直封边'
      ,[D31] as 'D31_异型线-直封边'
      ,[D32] as 'D32_斜边线-CNC'
      ,[D34] as 'D34_异型线-手工封边'
      ,[D37] as 'D37_异型线-毛刷组装'
      ,[D41] as 'D41_木工加工区'
      ,[D42] as 'D42_配套区'
      ,[D44] as 'D44_柜桶组装'
      ,[D47] as 'D47_柜子组装'
      ,[D51] as 'D51_包装'
      ,[D54] as 'D54_配件包装'     
  FROM [LamexMESManager].[dbo].[B_IE_WorkTimeHistory]
  where 1=1 " + s1.ToString() + "";

                DataTable dtList = BaseBuildSql.GetDataTableBySql(sql);

                GridControl grid = new GridControl();
                GridView view = new GridView();
                grid.ViewCollection.Add(view);
                grid.MainView = view;
                view.GridControl = grid;
                foreach (DataColumn dc in dtList.Columns)
                {
                    DevExpress.XtraGrid.Columns.GridColumn gridColumnNumber = view.Columns.AddVisible(dc.ColumnName);
                    gridColumnNumber.FieldName = dc.ColumnName;
                }
                grid.DataSource = dtList;
                this.Controls.Add(grid);
                grid.ForceInitialize();
                view.BestFitColumns();
                //view.OptionsPrint.PrintHorzLines = false;
                //view.OptionsPrint.PrintVertLines = false;
                view.ExportToText(fileDialog.FileName);
                // DevExpress.XtraEditors.XtraMessageBox.Show("导出成功！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                if (DevExpress.XtraEditors.XtraMessageBox.Show("导出成功，是否打开文件？", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    System.Diagnostics.Process.Start(fileDialog.FileName);//打开指定路径下的文件

            }
        }
        public void ExportToExcel(GridView gridView, string 文件名)
        {
            if (gridView.RowCount < 0) return;
            System.Data.DataTable dt = (gridView.DataSource as System.Data.DataView).Table;
            SaveFileDialog dlg = new SaveFileDialog();
            dlg.Filter = "Excel文件(*.xls)|*.xls";
            dlg.FilterIndex = 0;
            dlg.RestoreDirectory = true;            //dlg.CreatePrompt = true;            
            dlg.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
            dlg.FileName = string.Format("{0}_{1}", DateTime.Now.ToString("yyyy-MM-dd HH时mm分"), 文件名);
            if (dlg.ShowDialog() != DialogResult.OK) return;
            string filePath = dlg.FileName;
            using (DevExpress.Utils.WaitDialogForm wdf = new DevExpress.Utils.WaitDialogForm("请稍等", "正在导出数据...", new Size(400, 80)))
            {
                int OLDOFFICEVESION = -4143;
                int NEWOFFICEVESION = 56;                //保存excel文件的格式                
                int FormatNum;                //excel版本号                string Version;                //启动应用                
                Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
                System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
                Microsoft.Office.Interop.Excel.Workbooks workbooks = xlApp.Workbooks;                //创建文件                
                Microsoft.Office.Interop.Excel.Workbook workbook = workbooks.Add(Microsoft.Office.Interop.Excel.XlWBATemplate.xlWBATWorksheet);                //创建sheet                
                Microsoft.Office.Interop.Excel.Worksheet worksheet = (Microsoft.Office.Interop.Excel.Worksheet)workbook.Worksheets[1];                //获取你使用的excel 的版本号                
                Version = xlApp.Version;                //使用Excel 97-2003                
                if (Convert.ToDouble(value: Version) < 12)
                {
                    FormatNum = OLDOFFICEVESION;
                }                //使用 excel 2007或更新                
                else
                {
                    FormatNum = NEWOFFICEVESION;
                }
                //添加输出excel表格的表头信息信息                
                //注意这里的excel对应的单元格第一个位置为[1,1]，而不是我们平时定义[0,0]                
                for (int i = 0; i < gridView.Columns.Count; i++)
                {
                    worksheet.Cells[1, i + 1] = gridView.Columns[i].FieldName;
                }
                //添加输出excel表格的内容信息                
                for (int rowIndex = 1; rowIndex < dt.Rows.Count + 1; rowIndex++)
                {
                    DataRow rowArr = dt.Rows[rowIndex - 1];
                    for (int cellIndex = 0; cellIndex < gridView.Columns.Count; cellIndex++)
                    {
                        string aa = rowArr[cellIndex].ToString();
                        worksheet.Cells[rowIndex + 1, cellIndex + 1] = rowArr[gridView.Columns[cellIndex].FieldName];
                    }
                }
                //((Microsoft.Office.Interop.Excel.Range)worksheet.Cells[1, 1]).EntireColumn.Delete(0);
                ((Microsoft.Office.Interop.Excel.Range)worksheet.Cells[1, 3]).EntireColumn.Delete(0);
                ((Microsoft.Office.Interop.Excel.Range)worksheet.Cells[1, 3]).EntireColumn.Delete(0);
                ((Microsoft.Office.Interop.Excel.Range)worksheet.Cells[1, 3]).EntireColumn.Delete(0);
                ((Microsoft.Office.Interop.Excel.Range)worksheet.Cells[1, 3]).EntireColumn.Delete(0);
                ((Microsoft.Office.Interop.Excel.Range)worksheet.Cells[1, 3]).EntireColumn.Delete(0);
                ((Microsoft.Office.Interop.Excel.Range)worksheet.Cells[1, 3]).EntireColumn.Delete(0);
                ((Microsoft.Office.Interop.Excel.Range)worksheet.Cells[1, 3]).EntireColumn.Delete(0);
                //((Microsoft.Office.Interop.Excel.Range)worksheet.Cells[1, 2]).EntireColumn.Delete(0);
                //((Microsoft.Office.Interop.Excel.Range)worksheet.Cells[1, 2]).EntireColumn.Delete(0);
                //删除已存在的excel文件，否则会无法保存创建的excel文件                
                if (File.Exists(filePath))
                {
                    try
                    {
                        File.Delete(filePath);
                    }
                    catch (IOException e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }
                //保存，这里必须指定FormatNum文件的格式，否则无法打开创建的excel文件                
                workbook.SaveAs(filePath, FormatNum);
                //显示创建的excel文件，true打开Excel，false隐藏Excel                
                xlApp.Visible = false;                //关闭Excel进程                
                xlApp.Quit();
            }

        }


        #region"保存"
        public override void DoSave(IButtonInfo sender)
        {
            #region 按钮权限
            if (!BuildSqlHelper.IsExistList("B_IE_WorkTimeHistory", "LamexMESManager")) return;
            #endregion
            //try
            //{
            //    using (DevExpress.Utils.WaitDialogForm wdf = new DevExpress.Utils.WaitDialogForm("请稍等", "正在保存数据...", new Size(400, 80)))
            //    {
            //        Lamex.SIESystemManager.Model.B_IE_WorkTimeHistoryInfo workModel = new Model.B_IE_WorkTimeHistoryInfo();
            //        for (int i = 0; i < gridView2.RowCount; i++)
            //        {
            //            B_IE_WorkTimeHistoryInfo model = BaseFactory<B_IE_WorkTimeHistory>.Instance.GetEntriyList("1=1 and PartNumber='" + gridView2.GetRowCellDisplayText(i, "PART_NUMBER").ToString() + "'").FirstOrDefault();
            //            if (model == null)
            //            {
            //                workModel.PartNumber = gridView2.GetRowCellDisplayText(i, "PART_NUMBER").ToString();
            //                workModel.DrawNum = gridView2.GetRowCellDisplayText(i, "DRAWING_NUMBER").ToString();
            //                workModel.Width_1 = gridView2.GetRowCellDisplayText(i, "Width_1").ToString();
            //                workModel.Dedth_1 = gridView2.GetRowCellDisplayText(i, "Depth_1").ToString();
            //                workModel.Width_2 = gridView2.GetRowCellDisplayText(i, "Width_2").ToString();
            //                workModel.Dedth_2 = gridView2.GetRowCellDisplayText(i, "Depth_2").ToString();
            //                workModel.Tinckness = gridView2.GetRowCellDisplayText(i, "Thickness").ToString();
            //                workModel.D_Cutting_Size = gridView2.GetRowCellDisplayText(i, "D_Cutting_Size").ToString();
            //                workModel.WorkCenterNumber = gridView2.GetRowCellDisplayText(i, "WORKCENTER_NUMBER").ToString();
            //                workModel.Decription = gridView2.GetRowCellDisplayText(i, "DESCRIBE").ToString();
            //                workModel.GROUP_CODE = gridView2.GetRowCellDisplayText(i, "GROUP_CODE").ToString();
            //                workModel.CountDecription = gridView2.GetRowCellDisplayText(i, "CALCULATE_DESC").ToString();
            //                workModel.iCount = gridView2.GetRowCellDisplayText(i, "CALCULATES").ToString();
            //                workModel.Cycle = gridView2.GetRowCellDisplayText(i, "WEEKS").ToString();
            //                workModel.D01 = gridView2.GetRowCellDisplayText(i, "D01").ToString();
            //                workModel.D04 = gridView2.GetRowCellDisplayText(i, "D04").ToString();
            //                workModel.D07 = gridView2.GetRowCellDisplayText(i, "D07").ToString();
            //                workModel.D11 = gridView2.GetRowCellDisplayText(i, "D11").ToString();
            //                workModel.D14 = gridView2.GetRowCellDisplayText(i, "D14").ToString();
            //                workModel.D17 = gridView2.GetRowCellDisplayText(i, "D17").ToString();
            //                workModel.D21 = gridView2.GetRowCellDisplayText(i, "D21").ToString();
            //                workModel.D24 = gridView2.GetRowCellDisplayText(i, "D24").ToString();
            //                workModel.D30 = gridView2.GetRowCellDisplayText(i, "D30").ToString();
            //                workModel.D27 = gridView2.GetRowCellDisplayText(i, "D27").ToString();
            //                workModel.D28 = gridView2.GetRowCellDisplayText(i, "D28").ToString();
            //                workModel.D29 = gridView2.GetRowCellDisplayText(i, "D29").ToString();
            //                workModel.D31 = gridView2.GetRowCellDisplayText(i, "D31").ToString();
            //                workModel.D32 = gridView2.GetRowCellDisplayText(i, "D32").ToString();
            //                workModel.D34 = gridView2.GetRowCellDisplayText(i, "D34").ToString();
            //                workModel.D37 = gridView2.GetRowCellDisplayText(i, "D37").ToString();
            //                workModel.D41 = gridView2.GetRowCellDisplayText(i, "D41").ToString();
            //                workModel.D42 = gridView2.GetRowCellDisplayText(i, "D42").ToString();
            //                workModel.D44 = gridView2.GetRowCellDisplayText(i, "D44").ToString();
            //                workModel.D47 = gridView2.GetRowCellDisplayText(i, "D47").ToString();
            //                workModel.D51 = gridView2.GetRowCellDisplayText(i, "D51").ToString();
            //                workModel.D54 = gridView2.GetRowCellDisplayText(i, "D54").ToString();
            //                workModel.CreateDate = DateTime.Now;
            //                workModel.Flag = "1";
            //                BaseFactory<B_IE_WorkTimeHistory>.Instance.Insert(workModel);
            //            }
            //            else
            //            {
            //                model.PartNumber = gridView2.GetRowCellDisplayText(i, "PART_NUMBER").ToString();
            //                model.DrawNum = gridView2.GetRowCellDisplayText(i, "DRAWING_NUMBER").ToString();
            //                model.Width_1 = gridView2.GetRowCellDisplayText(i, "Width_1").ToString();
            //                model.Dedth_1 = gridView2.GetRowCellDisplayText(i, "Depth_1").ToString();
            //                model.Width_2 = gridView2.GetRowCellDisplayText(i, "Width_2").ToString();
            //                model.Dedth_2 = gridView2.GetRowCellDisplayText(i, "Depth_2").ToString();
            //                model.Tinckness = gridView2.GetRowCellDisplayText(i, "Thickness").ToString();
            //                model.D_Cutting_Size = gridView2.GetRowCellDisplayText(i, "D_Cutting_Size").ToString();
            //                model.WorkCenterNumber = gridView2.GetRowCellDisplayText(i, "WORKCENTER_NUMBER").ToString();
            //                model.Decription = gridView2.GetRowCellDisplayText(i, "DESCRIBE").ToString();
            //                model.GROUP_CODE = gridView2.GetRowCellDisplayText(i, "GROUP_CODE").ToString();
            //                model.CountDecription = gridView2.GetRowCellDisplayText(i, "CALCULATE_DESC").ToString();
            //                model.iCount = gridView2.GetRowCellDisplayText(i, "CALCULATES").ToString();
            //                model.Cycle = gridView2.GetRowCellDisplayText(i, "WEEKS").ToString();
            //                model.D01 = gridView2.GetRowCellDisplayText(i, "D01").ToString();
            //                model.D04 = gridView2.GetRowCellDisplayText(i, "D04").ToString();
            //                model.D07 = gridView2.GetRowCellDisplayText(i, "D07").ToString();
            //                model.D11 = gridView2.GetRowCellDisplayText(i, "D11").ToString();
            //                model.D14 = gridView2.GetRowCellDisplayText(i, "D14").ToString();
            //                model.D17 = gridView2.GetRowCellDisplayText(i, "D17").ToString();
            //                model.D21 = gridView2.GetRowCellDisplayText(i, "D21").ToString();
            //                model.D24 = gridView2.GetRowCellDisplayText(i, "D24").ToString();
            //                model.D30 = gridView2.GetRowCellDisplayText(i, "D30").ToString();
            //                model.D27 = gridView2.GetRowCellDisplayText(i, "D27").ToString();
            //                model.D28 = gridView2.GetRowCellDisplayText(i, "D28").ToString();
            //                model.D29 = gridView2.GetRowCellDisplayText(i, "D29").ToString();
            //                model.D31 = gridView2.GetRowCellDisplayText(i, "D31").ToString();
            //                model.D32 = gridView2.GetRowCellDisplayText(i, "D32").ToString();
            //                model.D34 = gridView2.GetRowCellDisplayText(i, "D34").ToString();
            //                model.D37 = gridView2.GetRowCellDisplayText(i, "D37").ToString();
            //                model.D41 = gridView2.GetRowCellDisplayText(i, "D41").ToString();
            //                model.D42 = gridView2.GetRowCellDisplayText(i, "D42").ToString();
            //                model.D44 = gridView2.GetRowCellDisplayText(i, "D44").ToString();
            //                model.D47 = gridView2.GetRowCellDisplayText(i, "D47").ToString();
            //                model.D51 = gridView2.GetRowCellDisplayText(i, "D51").ToString();
            //                model.D54 = gridView2.GetRowCellDisplayText(i, "D54").ToString();
            //                model.CreateDate = DateTime.Now;
            //                model.Flag = "1";
            //                BaseFactory<B_IE_WorkTimeHistory>.Instance.Update(model);
            //            }
            //        }

            //    }
            //    XtraMessageBox.Show("保存成功！");
            //}
            //catch (Exception ex)
            //{
            //    XtraMessageBox.Show("保存失败！");
            //}
            //base.DoSave(sender);
        }
        #endregion
    }
}
